package com.sleep.miniosleep.config;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;


/**
 * @ClassName MinIOConfig
 * @Description TODO
 * @Author 郭敖
 * @Date 2024年03月28日 15:22
 * @Version 1.0
 */
@AutoConfiguration
@ConditionalOnBean(MinIOProperty.class)
@ConditionalOnProperty(name = "minio.enable",havingValue = "true",matchIfMissing = true)
public class MyMinIOConfig {

    @Autowired
    private MinIOProperty minIOProperty;

    @Bean
    public MinioClient minioClient(){
        return MinioClient.builder()
                .endpoint(minIOProperty.getUrl())
                .credentials(minIOProperty.getAccessKey(),minIOProperty.getSecretKey()).build();
    }
}
